
#ifndef __TB67H450FNG_H__
#define __TB67H450FNG_H__

#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include "tb67h450_msp_init.h"
#include "sin_map.h"

#define OUT_AP_H() (GPIOB->BSRR = GPIO_PIN_10)
#define OUT_AP_L() (GPIOB->BRR  = GPIO_PIN_10)
#define OUT_AM_H() (GPIOB->BSRR = GPIO_PIN_11)
#define OUT_AM_L() (GPIOB->BRR  = GPIO_PIN_11)
#define OUT_BP_H() (GPIOB->BSRR = GPIO_PIN_12)
#define OUT_BP_L() (GPIOB->BRR  = GPIO_PIN_12)
#define OUT_BM_H() (GPIOB->BSRR = GPIO_PIN_13)
#define OUT_BM_L() (GPIOB->BRR  = GPIO_PIN_13)

#define OUT_PWM_TO_DAC_A(value) (__HAL_TIM_SET_COMPARE(&Tim4Handle, TIM_CHANNEL_1, value))
#define OUT_PWM_TO_DAC_B(value) (__HAL_TIM_SET_COMPARE(&Tim4Handle, TIM_CHANNEL_2, value))

typedef struct {
	unsigned short sinMapPtr;      // SIN 函数数组指针
	short sinMapData;              // SIN 函数换算数值
	unsigned short dacValue12Bits; // 12 位 DAC 数值
} FastSinToDac;

extern FastSinToDac phaseA;	// A 相电流控制
extern FastSinToDac phaseB;	// B 相电流控制

extern void TB67H450_DacOutputVoltage(unsigned short _voltageA_3300mVIn12bits, unsigned short _voltageB_3300mVIn12bits);
extern void TB67H450_SetInputA(unsigned char _statusAp, unsigned char _statusAm);
extern void TB67H450_SetInputB(unsigned char _statusBp, unsigned char _statusBm);
extern void TB67H450_SetSleep();
extern void TB67H450_SetBrake();
extern void TB67H450_SetTwoCoilsCurrent(unsigned short _currentA_3300mAIn12Bits, unsigned short _currentB_3300mAIn12Bits);
extern void TB67H450_SetFocCurrentVector(unsigned int _directionInCount, int _current_mA);

#endif
